<!doctype html>



  


<html class="theme-next muse use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="redis," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.1" />






<meta name="description" content="redis 3.x 集群搭建标签（空格分隔）： redis



编译安装
集群依赖
集群配置">
<meta property="og:type" content="article">
<meta property="og:title" content="redis3.x 集群搭建">
<meta property="og:url" content="http://yoursite.com/2016/09/21/redis-cluster/index.html">
<meta property="og:site_name" content="个人博客">
<meta property="og:description" content="redis 3.x 集群搭建标签（空格分隔）： redis



编译安装
集群依赖
集群配置">
<meta property="og:updated_time" content="2017-01-19T07:14:13.468Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="redis3.x 集群搭建">
<meta name="twitter:description" content="redis 3.x 集群搭建标签（空格分隔）： redis



编译安装
集群依赖
集群配置">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 0,
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="http://yoursite.com/2016/09/21/redis-cluster/"/>

  <title> redis3.x 集群搭建 | 个人博客 </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">个人博客</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">随便写点什么</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                redis3.x 集群搭建
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-09-21T11:28:28+08:00" content="2016-09-21">
              2016-09-21
            </time>
          </span>

          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/2016/09/21/redis-cluster/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2016/09/21/redis-cluster/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="redis-3-x-集群搭建"><a href="#redis-3-x-集群搭建" class="headerlink" title="redis 3.x 集群搭建"></a>redis 3.x 集群搭建</h1><p>标签（空格分隔）： redis</p>
<hr>
<blockquote>
<ul>
<li>编译安装</li>
<li>集群依赖</li>
<li>集群配置</li>
</ul>
</blockquote>
<a id="more"></a>
<hr>
<h2 id="编译安装"><a href="#编译安装" class="headerlink" title="编译安装"></a>编译安装</h2><p>编译redis源码<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">wget http://download.redis.io/redis-stable.tar.gz</div><div class="line">tar xvzf redis-stable.tar.gz</div><div class="line">cd redis-stable</div><div class="line">make</div></pre></td></tr></table></figure></p>
<h2 id="集群依赖"><a href="#集群依赖" class="headerlink" title="集群依赖"></a>集群依赖</h2><p>1.安装Ruby</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">#Mac</div><div class="line">brew instsall Ruby</div><div class="line"></div><div class="line">#其余（二选一）</div><div class="line">sudo apt-get install ruby-full</div><div class="line">sudo yum install ruby</div></pre></td></tr></table></figure>
<p>2.安装Ruby的Redis接口<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">sudo gem install redis</div></pre></td></tr></table></figure></p>
<p>否则建立集群关系是会抛出类似以下的错误<br><figure class="highlight ruby"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">custom_require.<span class="symbol">rb:</span><span class="number">36</span><span class="symbol">:in</span> <span class="string">`require': cannot load such file -- redis (LoadError)</span></div><div class="line">from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `<span class="keyword">require</span><span class="string">'</span></div><div class="line">from ./redis-trib.rb:25:in `&lt;main&gt;'</div></pre></td></tr></table></figure></p>
<h2 id="集群配置"><a href="#集群配置" class="headerlink" title="集群配置"></a>集群配置</h2><p> 进入第一步make之后的<strong>redis-stable/utils/create-cluster</strong>目录<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">./create-cluster start #启动预创建集群的节点实例</div></pre></td></tr></table></figure></p>
<p>节点的数量，节点的端口可以在<strong>create-cluster</strong>中配置<br>默认采用3主3从的方式来创建<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"># Settings</div><div class="line">PORT=30000 #端口</div><div class="line">TIMEOUT=2000 #超时时间</div><div class="line">NODES=6 #节点数量</div><div class="line">REPLICAS=1</div></pre></td></tr></table></figure></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">./create-cluster create #将各个节点实例组件成集群，调的是src/redis-trib.rb</div></pre></td></tr></table></figure>
<p>运行后若输出类似日志，则说明创建成功<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div></pre></td><td class="code"><pre><div class="line">&gt;&gt;&gt; Creating cluster</div><div class="line">&gt;&gt;&gt; Performing hash slots allocation on 6 nodes...</div><div class="line">Using 3 masters:</div><div class="line">127.0.0.1:30001</div><div class="line">127.0.0.1:30002</div><div class="line">127.0.0.1:30003</div><div class="line">Adding replica 127.0.0.1:30004 to 127.0.0.1:30001</div><div class="line">Adding replica 127.0.0.1:30005 to 127.0.0.1:30002</div><div class="line">Adding replica 127.0.0.1:30006 to 127.0.0.1:30003</div><div class="line">M: 24afed44137da8a7cf259f2678e5305b0185dbd3 127.0.0.1:30001</div><div class="line">   slots:0-5460 (5461 slots) master</div><div class="line">M: 12ddaf03059c6a3417170e30d7150401349a6047 127.0.0.1:30002</div><div class="line">   slots:5461-10922 (5462 slots) master</div><div class="line">M: 2b45999b2798c0e962f999c2ceeb239c41b8a7af 127.0.0.1:30003</div><div class="line">   slots:10923-16383 (5461 slots) master</div><div class="line">S: adfbb0f309c96a438e4b186bf00b07429306c1b0 127.0.0.1:30004</div><div class="line">   replicates 24afed44137da8a7cf259f2678e5305b0185dbd3</div><div class="line">S: b7589a63f95557cee1f50842f383180c4de2c7cd 127.0.0.1:30005</div><div class="line">   replicates 12ddaf03059c6a3417170e30d7150401349a6047</div><div class="line">S: fe5111d988e14b158638e15675e57298f5b37f43 127.0.0.1:30006</div><div class="line">   replicates 2b45999b2798c0e962f999c2ceeb239c41b8a7af</div><div class="line">Can I set the above configuration? (type &apos;yes&apos; to accept): yes</div><div class="line">&gt;&gt;&gt; Nodes configuration updated</div><div class="line">&gt;&gt;&gt; Assign a different config epoch to each node</div><div class="line">&gt;&gt;&gt; Sending CLUSTER MEET messages to join the cluster</div><div class="line">Waiting for the cluster to join.</div><div class="line">&gt;&gt;&gt; Performing Cluster Check (using node 127.0.0.1:30001)</div><div class="line">M: 24afed44137da8a7cf259f2678e5305b0185dbd3 127.0.0.1:30001</div><div class="line">   slots:0-5460 (5461 slots) master</div><div class="line">M: 12ddaf03059c6a3417170e30d7150401349a6047 127.0.0.1:30002</div><div class="line">   slots:5461-10922 (5462 slots) master</div><div class="line">M: 2b45999b2798c0e962f999c2ceeb239c41b8a7af 127.0.0.1:30003</div><div class="line">   slots:10923-16383 (5461 slots) master</div><div class="line">M: adfbb0f309c96a438e4b186bf00b07429306c1b0 127.0.0.1:30004</div><div class="line">   slots: (0 slots) master</div><div class="line">   replicates 24afed44137da8a7cf259f2678e5305b0185dbd3</div><div class="line">M: b7589a63f95557cee1f50842f383180c4de2c7cd 127.0.0.1:30005</div><div class="line">   slots: (0 slots) master</div><div class="line">   replicates 12ddaf03059c6a3417170e30d7150401349a6047</div><div class="line">M: fe5111d988e14b158638e15675e57298f5b37f43 127.0.0.1:30006</div><div class="line">   slots: (0 slots) master</div><div class="line">   replicates 2b45999b2798c0e962f999c2ceeb239c41b8a7af</div><div class="line">[OK] All nodes agree about slots configuration.</div><div class="line">&gt;&gt;&gt; Check for open slots...</div><div class="line">&gt;&gt;&gt; Check slots coverage...</div><div class="line">[OK] All 16384 slots covered.  #表示创建成功</div></pre></td></tr></table></figure></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">./create-clusher stop #停止集群</div></pre></td></tr></table></figure>
<h2 id="一些坑"><a href="#一些坑" class="headerlink" title="一些坑"></a>一些坑</h2><p>1.集群模式下，非master节点不接受任何读写操作，只被用于散列<br>2.此时不支持select：dbNum操作，不支持keys批量操作<br>3.client api中针对单机的api调用会报错</p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/redis/" rel="tag">#redis</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/09/19/redis-confguration/" rel="next" title="redis3.x配置文件详解">
                <i class="fa fa-chevron-left"></i> redis3.x配置文件详解
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2016/09/21/logback-configuration/" rel="prev" title="logback-configuration">
                logback-configuration <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2016/09/21/redis-cluster/"
           data-title="redis3.x 集群搭建" data-url="http://yoursite.com/2016/09/21/redis-cluster/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/uploads/touxiang.jpg"
               alt="钱伟峰" />
          <p class="site-author-name" itemprop="name">钱伟峰</p>
          <p class="site-description motion-element" itemprop="description">每天进步一点点</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">21</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">7</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">11</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#redis-3-x-集群搭建"><span class="nav-number">1.</span> <span class="nav-text">redis 3.x 集群搭建</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#编译安装"><span class="nav-number">1.1.</span> <span class="nav-text">编译安装</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#集群依赖"><span class="nav-number">1.2.</span> <span class="nav-text">集群依赖</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#集群配置"><span class="nav-number">1.3.</span> <span class="nav-text">集群配置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#一些坑"><span class="nav-number">1.4.</span> <span class="nav-text">一些坑</span></a></li></ol></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">钱伟峰</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>

        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.1"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"qianweifeng"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    <script src="/vendors/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  






  
  

  

  

  

</body>
</html>
